package com.yaozheng.vocationaltraining.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.VideoView;

public class CustomVideoView extends VideoView {
	private PlayPauseListener mListener;
	private int minWidth, minHeight;

	public int getMinWidth() {
		return minWidth;
	}

	public void setMinWidth(int minWidth) {
		this.minWidth = minWidth;
	}

	public int getMinHeight() {
		return minHeight;
	}

	public void setMinHeight(int minHeight) {
		this.minHeight = minHeight;
	}

	public PlayPauseListener getmListener() {
		return mListener;
	}

	public void setmListener(PlayPauseListener mListener) {
		this.mListener = mListener;
	}

	public CustomVideoView(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		// TODO Auto-generated constructor stub
	}

	public CustomVideoView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}

	public CustomVideoView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void pause() {
		super.pause();
		if (mListener != null) {
			mListener.onPause();
		}
	}

	@Override
	public void start() {
		super.start();
		if (mListener != null) {
			mListener.onPlay();
		}
	}

	// 控制VideoView的可显示区域 2个参数是VideoView实际可现实区域的宽和高
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		// 从2者中取得较大的那个
		int width = getDefaultSize(minWidth, widthMeasureSpec);
		int height = getDefaultSize(minHeight, heightMeasureSpec);
		this.setMeasuredDimension(width, height);
	}

	public static interface PlayPauseListener {
		void onPlay();

		void onPause();
	}
}
